<?php
/**
 *  @brief Xử lý liên quan đến bài viết
 *  
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Comment_m extends Base_model {
	
	public $primary_key = 'comment_ID';
	public $validate = array(
        array( 'field' => 'comment_post_ID',	
               'label' => 'comment_post_ID',
               'rules' => 'trim|required' ),
        array( 'field' => 'comment_author',
               'label' => 'comment_author'),
    );
	public function __construct()
	{
		parent::__construct();
	}
	
	function loadmeta() {
		$this->postmeta->_get_meta_table("comments");
	}
	
	function get_comments($args = array()) {
		$default = array(
			'orderby'          => 'comments.comment_date',
			'order'            => 'DESC',
			'comment_post_ID'	=> '',
			);
		$r = array_merge_key($args, $default);			
		if(isset($r['comment_post_ID'])){
			$this->where('comment_post_ID', $r['comment_post_ID']);
		}
		$this->order_by($r['orderby'], $r['order']);
		return $this->get_many_by();
	}
}